import * as types from "./constants";
import { loadCategorySongs, getCategory as loadCategory } from "@/api/songs";
import { handleCategory } from "@/utils/handle-data";
const changeCategorySongsAct = res => ({
    type: types.CHANGE_CATEGORY_SONGS,
    categorySongs: res
});
export const changeCurrentCategoryAct = name => ({
    type: types.CHANGE_CURRENT_CATEGORY,
    currentCategory: name
});

const changeCategoryAct = res => ({
    type: types.CHANGE_CATEGORY,
    category: res
});
export const getCategory = () => {
    return dispatch => {
        loadCategory().then(res => {
            if (res.code === 200) {
                const categoryData = handleCategory(res);
                dispatch(changeCategoryAct(categoryData));
            }
        });
    };
};
export const getCategorySongsAction = (page, value, order) => {
    return (dispatch, getState) => {
        const name = value || getState().getIn(["songs", "currentCategory"]);
        loadCategorySongs(name, (page - 1) * types.PAGE_SIZE, order).then(res => {
            if (res.code === 200) {
                dispatch(changeCategorySongsAct(res));
            }
        });
    };
};